<?php
namespace Friend\Controller;
use Common\Controller\CommonController;

/**
 * 黑名单模块
 */
class BlackListController extends CommonController {
	
	protected function _initialize(){
		parent::_initialize();
		$this->_mycache = S(C('REDIS_DSN'));
		$this->_auth();
		
		$this->_moduleid = 102;
		$this->_cust_blacklist = new \Common\Model\CustBlackListModel();
	}
    
	/**
	 * 获取黑名单列表
	 */
    public function getBlackListAction(){
		$this->_getBlackList();
    }
    
    private function _getBlackList(){
    	$blacklist = $this->_cust_blacklist->getBlacklistIdsByCustId($this->_custInfo['custid']);
    	if(!empty($blacklist)){
    		foreach($blacklist as &$cust){
    			$custInfo = $this->_getCustInfo($cust['tcustid']);
    			$cust['nickname'] = $custInfo['nickname'];
    			$cust['realname'] = $custInfo['realname'];
    			$cust['sex'] = $custInfo['sex'];
    		}
    	}else{
    		$blacklist = [];
    	}
    	
    	$this->data = $blacklist;
    	
    	$this->outPut();
    }
    
    
    /**
     * 添加黑名单
     */
    public function addBlackListAction(){
    	$tcustid = (int)I('request.tcustid');
    	$this->_addBlackList($tcustid);
    }
    
    private function _addBlackList($tcustid){
    	if(empty($tcustid)){
    		$this->status = 1000;
    		$this->msg = L('STATUS_1000');
    		$this->outPut();
    	}
    	
    	$data['custid'] = $this->_custInfo['custid'];
    	$data['tcustid'] = $tcustid;
    	$this->_cust_blacklist->addBlacklist($data);
    	 
    	$this->outPut();
    }
    
    
    /**
     * 删除黑名单
     */
    public function delBlackListAction(){
    	$tcustid = (int)I('request.tcustid');
    	$this->_delBlackList($tcustid);
    }
    
    private function _delBlackList($tcustid){
    	if(empty($tcustid)){
    		$this->status = 1000;
    		$this->msg = L('STATUS_1000');
    		$this->outPut();
    	}
    	 
    	$data['custid'] = $this->_custInfo['custid'];
    	$data['tcustid'] = $tcustid;
    	$this->_cust_blacklist->deleteBlacklist($data);
    
    	$this->outPut();
    }
}
